---
# Tasks to set up varnish

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - varnish
  - make
  tags:
  - varnish
  - packages

- name: set some varnishd selinux boolean
  seboolean: name=varnishd_connect_any persistent=yes state=yes
  tags:
  - varnish
  - selinux

- name: set domain_can_mmap_files selinux boolean
  seboolean: name=domain_can_mmap_files persistent=yes state=yes
  tags:
  - varnish
  - selinux

- name: install varnish /etc/sysconfig/varnish file (el7)
  copy: src=varnish.el7 dest=/etc/sysconfig/varnish owner=root group=root
  notify:
  - restart varnish
  tags:
  - varnish
  when: ansible_distribution_major_version|int == 7 and ansible_distribution == 'RedHat'

- name: install varnish /etc/systemd/system/varnish.service file (fedora 29+)
  template: src=varnish.f29.j2 dest=/etc/systemd/system/varnish.service owner=root group=root
  notify:
  - reload systemd
  - restart varnish
  tags:
  - varnish
  when: ansible_distribution_major_version|int >= 29 and ansible_distribution == 'Fedora'

- name: install /etc/varnish/default.vcl (proxies)
  template: src={{ varnish_group }}.vcl.j2 dest=/etc/varnish/default.vcl owner=root group=root
  notify:
  - restart varnish
  tags:
  - varnish

- name: make sure varnish is set to enabled on boot
  service: enabled=yes name=varnish
  tags:
  - varnish
